# -*- coding: utf-8 -*-
# @version : 1.0
# @File    : user.py
# @Date    : 2024/9/27 13:07
# @Author  : GlenZhao
# @Desc    :
from pydantic import BaseModel, ConfigDict

from apps.auth.user.schemas.role import RoleSimpleOut
from core.data_types import DatetimeStr, Telephone, Email
from db.base import BaseSchemas


class User(BaseModel):
    name: str
    telephone: Telephone
    email: Email | None = None
    nickname: str | None = None
    avatar: str | None = None
    is_active: bool | None = True
    is_staff: bool | None = True
    gender: str | None = "0"
    is_wx_server_openid: bool | None = False


class UserSimpleOut(User, BaseSchemas):
    model_config = ConfigDict(from_attributes=True)

    is_reset_password: bool | None = None
    last_login: DatetimeStr | None = None
    last_ip: str | None = None


class UserRolesOut(UserSimpleOut):
    model_config = ConfigDict(from_attributes=True)
    roles: list[RoleSimpleOut] = []
    permissions: list[str] = ["*:*:*"]


class UserFullOut(UserSimpleOut):
    model_config = ConfigDict(from_attributes=True)
    roles: list[RoleSimpleOut] = []


class UserCache(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    name: str | None = None
    nickname: str | None = None
    avatar: str | None = None
    telephone: str | None = None
    email: str | None = None
    roles: list[RoleSimpleOut] = []


class GenCaptureIn(BaseModel):
    telephone: Telephone


class LoginIn(BaseModel):
    telephone: Telephone
    captcha: str


class MetaUserRegister(BaseModel):
    code: str


class TokenRefresh(BaseModel):
    refresh: str


class TokenPayload(BaseModel):
    id: int
    avatar: str
    name: str
    is_refresh: bool


class UpdateUserIn(BaseModel):
    id: int | None = None
    name: str | None = None
    avatar: str | None = None
    role_ids: list[int] = []

